from customer import Customer


class Cms:
    def __init__(self):
        self.customers = {}

    def add_customer(self):
        c_id = input("请输入客户ID：")
        if c_id in self.customers:
            raise ValueError("Customer ID already exists")
        customer = Customer()
        customer.c_id = c_id
        customer.set_name(input("请输入客户姓名："))
        customer.set_age(input("请输入客户年龄："))
        customer.set_gender(input("请输入客户性别："))
        customer.set_phone(input("请输入客户手机号："))
        self.customers[customer.c_id] = customer
        return customer.c_id

    def remove_customer(self, c_id):
        if c_id not in self.customers:
            raise ValueError("Customer ID does not exist")
        del self.customers[c_id]
        return True

    def update_customer(self):
        c_id = input("请输入要修改的客户id")
        if c_id not in self.customers:
            raise ValueError("Customer does not exist")
        else:
            customer = Customer()
            customer.c_id = c_id
            name = input("请输入客户姓名：")
            customer.set_name(name if name is not None and name != "" else self.customers[c_id].name)
            age = input("请输入客户年龄：")
            customer.set_age(age if age is not None and age != "" else self.customers[c_id].age)
            gender = input("请输入客户性别：")
            customer.set_gender(gender if gender is not None and gender != "" else self.customers[c_id].gender)
            phone = input("请输入客户手机号：")
            customer.set_phone(phone if phone is not None and phone != "" else self.customers[c_id].phone)
            self.customers[c_id] = customer
        return True

    def search_customer(self, c_id):
        if c_id is None or c_id == "":
            return self.show_customers()
        if len(self.customers) == 0:
            return {}
        return self.customers.get(c_id)

    def show_customers(self):
        return self.customers